{extend name="public/base"}

{block name="title"}就行天下-消息{/block}

{block name="style"}
<link rel="stylesheet" href="__STATIC__/home/css/message.css" />
{/block}

{block name="main"}
<div class="pageControl inform">
    <div class="main-top"></div>
    <div class="msui_nav msui_navTop">
        <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back"></i></a>
        <h1 class="msui_navTop-title">通知</h1>
        <a href="" class="msui_navTop-right msui_navTop-cnav"><i class="micon-cnav"></i></a>
    </div>
    <a href="javascript:;" class="weui-cell weui-cell_access sys_msg">
        <div class="weui-cell__hd">
            <img src="__STATIC__/home/images/sy.png" alt="">
        </div>
        <div class="weui-cell__bd">
            <p class="fs065 cl-3333">系统通知</p>
            <p class="fs065 cl-9999">购买过程中的相关信息都会显示在这里哦</p>
        </div>
        <div class="weui-cell__ft">

        </div>
    </a>
    {volist name="list" id="vo"}
    <a href="{eq name='vo.type' value='1'}{:url('rong/index', ['targetId' => $vo['targetId']])}{else /}{:url('activity/group_chat', ['id' => $vo.id])}{/eq}" class="weui-cell weui-cell_access" data-targetId="{$vo.targetId}">
        <div class="weui-cell__hd userImg">
            <img src="{$vo.headimgurl}" alt="">
        </div>
        <div class="weui-cell__bd">
            <p class="fs065 cl-3333">{$vo.nickname}</p>
            <p class="fs065 cl-9999 rong_msg">{$vo.msg}</p>
        </div>
        <div class="weui-cell__ft">

        </div>
    </a>
    {/volist}
</div>
{/block}

{block name="javascript"}
<script src="__STATIC__/rong/dist/assets/js/RongIMLib.js"></script>
<script>
    $(function(){
        /**
         * 开始融云业务逻辑
         * @type {{appKey, token, navi}}
         */
        var params = {
            appKey : '{$Think.config.rong.app_key}',
            token : '{$data.token}',
            navi : ''
        };

        var userId = "";

        var callbacks = {
            getInstance : function(instance){
            },
            getCurrentUser : function(userInfo){
                console.log(userInfo.userId);
                userId = userInfo.userId;
//                alert("链接成功；userid=" + userInfo.userId);
            },
            receiveNewMessage : function(message){
                //判断是否有 @ 自己的消息
                var mentionedInfo = message.content.mentionedInfo || {};
                var ids = mentionedInfo.userIdList || [];
                for(var i=0; i < ids.length; i++){
                    if( ids[i] == userId){
                        alert("有人 @ 了你！");
                    }
                }

                if ($('a[data-targetId="'+ message.targetId +'"]').length > 0) {
                    $('a[data-targetId="'+ message.targetId +'"]').find('.rong_msg').text(message.content.content);
                    if ($('a[data-targetId="'+ message.targetId +'"]').find('.message_count_rong').length > 0)
                        $('a[data-targetId="'+ message.targetId +'"]').find('.message_count_rong').text(parseFloat($('a[data-targetId="'+ message.targetId +'"]').find('.message_count_rong').text()) + 1);
                    else
                        $('a[data-targetId="'+ message.targetId +'"]').find('.weui-cell__ft').html('<i class="message_count_rong">1</i>');
                } else {
                    $.get('{:url("get_rong_member_info")}', {userId : message.targetId}, function (msg) {
                        var html = '';
                        if (msg.code == 200) {
                            html += '<a href="/index/rong/index/targetId/'+ message.targetId +'.html" class="weui-cell weui-cell_access" data-targetId="'+ message.targetId +'">';
                            html += '   <div class="weui-cell__hd userImg">';
                            html += '   <img src="'+ msg.data.headimgurl +'" alt="">';
                            html += '   </div>';
                            html += '   <div class="weui-cell__bd">';
                            html += '   <p class="fs065 cl-3333">'+ msg.data.nickname +'</p>';
                            html += '<p class="fs065 cl-9999 rong_msg">'+ message.content.content +'</p>';
                            html += '</div>';
                            html += '<div class="weui-cell__ft"><i class="message_count_rong">1</i></div>';
                            html += '</a>';
                        }
                        $(".sys_msg").after(html);
                    }, 'json');
                }
                console.log(message);
            }
        };

        rong_init(params,callbacks);
    });
</script>
{/block}